package com.example.airole.tts.util;

import com.baidu.aip.speech.AipSpeech;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 百度TTS认证工具类
 */
@Slf4j
@Component
public class BaiduTTSAuthUtil {
    
    private AipSpeech client;
    private String appId;
    private String apiKey;
    private String secretKey;
    
    /**
     * 初始化百度TTS客户端
     */
    public void initClient(String appId, String apiKey, String secretKey) {
        this.appId = appId;
        this.apiKey = apiKey;
        this.secretKey = secretKey;
        
        // 初始化AipSpeech
        client = new AipSpeech(appId, apiKey, secretKey);
        
        // 设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        
        log.info("百度TTS客户端初始化成功, AppId: {}", appId);
    }
    
    /**
     * 获取百度TTS客户端
     */
    public AipSpeech getClient() {
        if (client == null) {
            throw new RuntimeException("百度TTS客户端未初始化，请先调用initClient方法");
        }
        return client;
    }
    
    /**
     * 检查客户端是否已初始化
     */
    public boolean isInitialized() {
        return client != null;
    }
    
    /**
     * 获取AppId
     */
    public String getAppId() {
        return appId;
    }
    
    /**
     * 获取ApiKey
     */
    public String getApiKey() {
        return apiKey;
    }
    
    /**
     * 获取SecretKey
     */
    public String getSecretKey() {
        return secretKey;
    }
}
